import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    cartList: [],
    photoListId: '',
    newsListId: '',
    goodsListId: '',
    comList: [],
    picList: [],
    active: 0,
    arr: []
  },
  plugins: [
    createPersistedState()
  ],
  mutations: {
    addCarItem (state, item) {
      state.arr.push(item)
      state.cartList = JSON.parse(JSON.stringify(state.arr))
    },
    setCartList (state, data) {
      state.cartList = data
    },
    setPhotoListId (state, id) {
      state.photoListId = id
    },
    setNewsListId (state, id) {
      state.newsListId = id
    },
    setGoodsListId (state, id) {
      state.goodsListId = id
    },
    clearCart (state) {
      state.arr = []
      state.cartList = []
    },
    updateCartItem (state, data) {
      state.cartList = data
    },
    setCommentList (state, data) {
      state.comList = data
    },
    setNewsList (state, data) {
      state.comList = data
    },
    setPicture (state, data) {
      state.picList = data
    },
    setVipActive (state, data) {
      state.active = data
    }
  },
  actions: {
  },
  modules: {
  }
})
